/*
 * Created on 2005-3-28
 *
 */
package com.hd123.rumba.catalog;

import com.hd123.rumba.exception.StringTooLongException;
import com.hd123.rumba.runtime.BaseEntity;

/**
 * @author caili
 */
public class Catalog extends BaseEntity implements ICatalog {
  private String code;
  private String name;
  /**
   * 该目录容纳的对象类型
   */
  private String itemType;
  /**
   * 是否主目录. 具有相同对象类型(ItemType)的目录中有且只有一个是主目录. 当设置一个目录为主目录时,
   * 相同对象类型的其它目录都被设置为非主目录.
   */
  private Boolean isMaster;
  /**
   * 目录中的类别按照ID位来分级别.
   */
  private int level1Length;
  private int level2Length;
  private int level3Length;
  private int level4Length;

  public static final int LENGTH_CODE = 20;
  public static final int LENGTH_NAME = 50;
  public static final int LENGTH_ITEMTYPE = 50;

  public String getCode() {
    return code;
  }

  public void setCode(String code) throws StringTooLongException {
    if (code != null) {
      code = code.trim().toUpperCase();
      code = truncate(code, LENGTH_CODE, "code", CAPTION_CODE);
    }
    this.code = code;
  }

  public String getItemType() {
    return itemType;
  }

  public void setItemType(String itemType) throws StringTooLongException {
    if (itemType != null)
      itemType = truncate(itemType, LENGTH_ITEMTYPE, "itemType", CAPTION_ITEMTYPE);
    this.itemType = itemType;
  }

  public int getLevel1Length() {
    return level1Length;
  }

  public void setLevel1Length(int level1Length) {
    this.level1Length = level1Length;
  }

  public int getLevel2Length() {
    return level2Length;
  }

  public void setLevel2Length(int level2Length) {
    this.level2Length = level2Length;
  }

  public int getLevel3Length() {
    return level3Length;
  }

  public void setLevel3Length(int level3Length) {
    this.level3Length = level3Length;
  }

  public int getLevel4Length() {
    return level4Length;
  }

  public void setLevel4Length(int level4Length) {
    this.level4Length = level4Length;
  }

  public Boolean isMaster() {
    return isMaster;
  }

  public void setMaster(Boolean isMaster) {
    this.isMaster = isMaster;
  }

  public Boolean getIsMaster() {
    return isMaster;
  }

  public void setIsMaster(Boolean isMaster) {
    this.isMaster = isMaster;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) throws StringTooLongException {
    if (name != null) {
      name = truncate(name, LENGTH_NAME, "name", CAPTION_NAME);
    }
    this.name = name;
  }
}
